﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.Model.Register;
using System.Data;
using Register.DBUtility;
using Register.IDAL;

namespace Register.DAL
{
    class RegistrationFeeInfoDAL : IRegistrationFeeInfoDAL
    {
        string tableName = "System_registrationFee";
        /// <summary>
        /// 增加一条数据
        /// </summary>
       
        public bool Add(RegistrationFee model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into System_registrationFee(");
            strSql.Append("RegistrationFee_ID,Hospital_ID,RegistrationFee_OutpatientType,RegistrationFee_Menory,RegistrationFee_Status,RegistrationFee_AddTime,RegistrationFee_Recoder,RegistrationFee_LastAmendTime,RegistrationFee_LastAmendPerson)");
            strSql.Append(" values (");
            strSql.Append("@RegistrationFee_ID,@Hospital_ID,@RegistrationFee_OutpatientType,@RegistrationFee_Menory,@RegistrationFee_Status,@RegistrationFee_AddTime,@RegistrationFee_Recoder,@RegistrationFee_LastAmendTime,@RegistrationFee_LastAmendPerson)");
            SqlParameter[] parameters = {
					new SqlParameter("@RegistrationFee_ID", SqlDbType.Char,5),
					new SqlParameter("@Hospital_ID", SqlDbType.Char,5),
					new SqlParameter("@RegistrationFee_OutpatientType", SqlDbType.Char,4),
					new SqlParameter("@RegistrationFee_Menory", SqlDbType.Money,8),
					new SqlParameter("@RegistrationFee_Status", SqlDbType.Char,1),
					new SqlParameter("@RegistrationFee_AddTime", SqlDbType.DateTime),
					new SqlParameter("@RegistrationFee_Recoder", SqlDbType.VarChar,20),
					new SqlParameter("@RegistrationFee_LastAmendTime", SqlDbType.DateTime),
					new SqlParameter("@RegistrationFee_LastAmendPerson", SqlDbType.VarChar,20)};
            parameters[0].Value = model.RegistrationFee_ID;
            parameters[1].Value = model.Hospital_ID;
            parameters[2].Value = model.RegistrationFee_OutpatientType;
            parameters[3].Value = model.RegistrationFee_Menory;
            parameters[4].Value = model.RegistrationFee_Status;
            parameters[5].Value = model.RegistrationFee_AddTime;
            parameters[6].Value = model.RegistrationFee_Recoder;
            parameters[7].Value = model.RegistrationFee_LastAmendTime;
            parameters[8].Value = model.RegistrationFee_LastAmendPerson;

            if (DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        
        public bool Update(RegistrationFee model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update System_registrationFee set ");
            strSql.Append("Hospital_ID=@Hospital_ID,");
            strSql.Append("RegistrationFee_OutpatientType=@RegistrationFee_OutpatientType,");
            strSql.Append("RegistrationFee_Menory=@RegistrationFee_Menory,");
            strSql.Append("RegistrationFee_Status=@RegistrationFee_Status,");
            //strSql.Append("RegistrationFee_AddTime=@RegistrationFee_AddTime,");
            //strSql.Append("RegistrationFee_Recoder=@RegistrationFee_Recoder,");
            strSql.Append("RegistrationFee_LastAmendTime=@RegistrationFee_LastAmendTime,");
            strSql.Append("RegistrationFee_LastAmendPerson=@RegistrationFee_LastAmendPerson");
            strSql.Append(" where RegistrationFee_ID=@RegistrationFee_ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@Hospital_ID", SqlDbType.Char,5),
					new SqlParameter("@RegistrationFee_OutpatientType", SqlDbType.Char,4),
					new SqlParameter("@RegistrationFee_Menory", SqlDbType.Money,8),
					new SqlParameter("@RegistrationFee_Status", SqlDbType.Char,1),
                    //new SqlParameter("@RegistrationFee_AddTime", SqlDbType.DateTime),
                    //new SqlParameter("@RegistrationFee_Recoder", SqlDbType.VarChar,20),
					new SqlParameter("@RegistrationFee_LastAmendTime", SqlDbType.DateTime),
					new SqlParameter("@RegistrationFee_LastAmendPerson", SqlDbType.VarChar,20),
					new SqlParameter("@RegistrationFee_ID", SqlDbType.Char,5)};
            parameters[0].Value = model.Hospital_ID;
            parameters[1].Value = model.RegistrationFee_OutpatientType;
            parameters[2].Value = model.RegistrationFee_Menory;
            parameters[3].Value = model.RegistrationFee_Status;
            //parameters[4].Value = model.RegistrationFee_AddTime;
            //parameters[5].Value = model.RegistrationFee_Recoder;
            parameters[4].Value = model.RegistrationFee_LastAmendTime;
            parameters[5].Value = model.RegistrationFee_LastAmendPerson;
            parameters[6].Value = model.RegistrationFee_ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string RegistrationFee_ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from System_registrationFee ");
            strSql.Append(" where RegistrationFee_ID=@RegistrationFee_ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@RegistrationFee_ID", SqlDbType.Char,5)};
            parameters[0].Value = RegistrationFee_ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到分页和查询后的数据
        /// </summary>
        public List<RegistrationFee> GetAllRegistrationFee(string where, int pageIndex, int size)
        {
            DataSet set = DbHelperSQL.getPagedData("*", "RegistrationFee_AddTime", where, tableName, OrderBy.DESC, pageIndex, size);
            List<RegistrationFee> list = ChangeReaderToList(set);
            return list;
        }
        private List<RegistrationFee> ChangeReaderToList(DataSet set)
        {
            List<RegistrationFee> list = new List<RegistrationFee>();
            DataTable table = set.Tables[0];
            foreach (DataRow row in table.Rows)
            {
                RegistrationFee registrationFee = new RegistrationFee();
                registrationFee.Hospital_ID = (string)row["Hospital_ID"];
                registrationFee.RegistrationFee_AddTime = (DateTime)row["RegistrationFee_AddTime"];
                registrationFee.RegistrationFee_ID = (string)row["RegistrationFee_ID"];
                registrationFee.RegistrationFee_LastAmendPerson = (string)row["RegistrationFee_LastAmendPerson"];
                registrationFee.RegistrationFee_LastAmendTime = (DateTime)row["RegistrationFee_LastAmendTime"];
                registrationFee.RegistrationFee_Menory = (decimal)row["RegistrationFee_Menory"];
                registrationFee.RegistrationFee_OutpatientType = (string)row["RegistrationFee_OutpatientType"];
                registrationFee.RegistrationFee_Recoder = (string)row["RegistrationFee_Recoder"];
                registrationFee.RegistrationFee_Status = (string)row["RegistrationFee_Status"];
                list.Add(registrationFee);
            }
            return list;
        }
        public int GetRoleCount(string where)
        {
            int count = 0;
            StringBuilder str = new StringBuilder();
            str.Append(" select count(*) from ");
            str.Append(tableName);
            if (where != null)
            {
                str.Append(" where ");
                str.Append(where);
                count = (int)DbHelperSQL.GetSingle(str.ToString());
            }
            else
            {
                count = (int)DbHelperSQL.GetSingle(str.ToString());
            }
            return count;
        }



    }
}
